﻿package mortal.game.view.guildNew.otherGuildMem
{
    import Message.Game.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.events.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.game.view.guildNew.member.*;
    import mortal.mvc.core.*;

    public class GuildNewOtherGMemPanel extends GSprite
    {
        protected var _bg:ScaleBitmap;
        protected var _titleSp:GuildNewMemTitleSp;
        protected var _list:GTileList;
        protected var _pageSelecter:PageSelecter;
        protected var _numDes:GTextFiled;
        protected var _num:GTextFiled;
        private var _sortFunction:Function;
        private var _memInfo:SelfGuildInfo;
        private static const PAGE_MEMBER_COUNT:int = 12;

        public function GuildNewOtherGMemPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._titleSp = UIFactory.getUICompoment(GuildNewMemTitleSp, -2, 1, this);
            this._bg = UIFactory.bg(0, 0, 745, 475, this, ImagesConst.PanelBg);
            this._list = UIFactory.tileList(0, 27, 760, 408, this);
            this._list.direction = GBoxDirection.VERTICAL;
            this._list.verticalGap = 0;
            this._list.horizontalGap = 0;
            this._list.rowHeight = 34;
            this._list.columnWidth = 745;
            this._list.columnCount = 1;
            this._list.rowCount = 12;
            this._list.width = 760;
            this._list.setStyle("cellRenderer", GuildNewMemberCell);
            this._pageSelecter = UIFactory.pageSelecter(315, 443, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.ComboBg, GlobalStyle.textFormatBai.center());
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.pageTextBoxSize = 36;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._numDes = UIFactory.gTextField("" + Language.getString(71597), 464, 444, 80, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._num = UIFactory.gTextField("20/80", 527, 444, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._sortFunction = GuildUtil.defaultMemberListSortFunc;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._titleSp.dispose(param1);
            this._bg = null;
            this._list = null;
            this._pageSelecter = null;
            this._numDes = null;
            this._num = null;
            GuildNewUtil.watachGuildId = 0;
            this._sortFunction = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function reqInfo() : void
        {
            if (this._list == null)
            {
                return;
            }
            var _loc_1:* = GuildNewUtil.watachGuildId;
            if (_loc_1 != 0)
            {
                Dispatcher.dispatchEvent(new DataEvent(GuildNewLocalEvent.GuildNewGetOtherGuildList, _loc_1));
            }
            return;
        }// end function

        public function updateMemList() : void
        {
            var _loc_5:int = 0;
            var _loc_6:SGuildMember = null;
            this._memInfo = Cache.instance.guild.otherGuildInfoV2;
            if (this._memInfo == null)
            {
                return;
            }
            this._sortFunction = this._titleSp.sortFunction;
            if (this._sortFunction == null)
            {
                this._sortFunction = GuildUtil.defaultMemberListSortFunc;
            }
            this._memInfo.memberList.sort(this._sortFunction);
            this._pageSelecter.maxPage = Math.ceil(this._memInfo.memberList.length / PAGE_MEMBER_COUNT);
            var _loc_1:* = (this._pageSelecter.currentPage - 1) * PAGE_MEMBER_COUNT;
            var _loc_2:* = new DataProvider();
            var _loc_3:int = 0;
            while (_loc_3 < PAGE_MEMBER_COUNT)
            {
                
                _loc_5 = _loc_1 + _loc_3;
                if (_loc_5 >= this._memInfo.memberList.length)
                {
                    break;
                }
                _loc_6 = this._memInfo.memberList[_loc_5];
                _loc_2.addItem(_loc_6);
                _loc_3++;
            }
            this._list.dataProvider = _loc_2;
            this._list.drawNow();
            var _loc_4:* = int(Cache.instance.guild.guildTotalNum[this._memInfo.guildID]);
            if (_loc_4 != 0)
            {
                this._num.text = "" + this._memInfo.memberList.length + "/" + _loc_4;
            }
            else
            {
                this._num.text = "" + this._memInfo.memberList.length;
            }
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateMemList();
            return;
        }// end function

    }
}
